/*!
 * \file	qong.c
 * \brief	Main program file for Qong.
 * \author	Jon "delrio" Cox
 * \date	February 4, 2011
 */

//------------------------------------------------------------------------//
//  Qong                                                                  //
//  Copyright (C) 2011 Jon Cox                                            //
//                                                                        //
//  This program is free software: you can redistribute it and/or modify  //
//  it under the terms of the GNU General Public License as published by  //
//  the Free Software Foundation, either version 3 of the License, or     //
//  (at your option) any later version.                                   //
//                                                                        //
//  This program is distributed in the hope that it will be useful,       //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of        //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
//  GNU General Public License for more details.                          //
//                                                                        //
//  You should have received a copy of the GNU General Public License     //
//  along with this program.  If not, see <http://www.gnu.org/licenses/>. //
//------------------------------------------------------------------------//

#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <game.h>
#include <types.h>
#include <graphics.h>
#include <defines.h>
#include <menu.h>
// FIXME: Drop the GL/ from these once we can get it to compile like that.
#include <GL/gl.h>
#include <GL/glu.h>

//! Pointer to the surface we will use to draw.
SDL_Surface *screen;

/*!
 * \brief	The main program.
 * \param argc	Argument count.
 * \param argv Argument values.
 * \return 0 if no errors showed up.
 */
int main( int argc, char **argv )
{
	bool_t running = true;
	mSelect_t action = m_NONE;

	if ( !initVideo( screen, 0 ) )
	{
		return 1;
	}
	printf( "SDL initialized successfully.\n" );

	// OpenGL display setup.
	glEnable( GL_TEXTURE_2D );
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
	glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
	glClear( GL_COLOR_BUFFER_BIT );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glOrtho( 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, -1.0f, 1.1f );

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	
	// Potentially place an intro screen here.

	// Always go to the main menu.
	action = menuMain();

	// Main loop.
	while( running )
	{
		switch ( action )
		{
			// The user wants to leave now.
			case m_QUIT:
				action = menuConfirmQuit();
				if ( action == m_YES )
				{
					action == m_FORCEQUIT;
				}
				break;
			// The user REALLY wants to leave now.
			case m_FORCEQUIT:
				// Note: this is just in case we NEED graceful
				// quitting.
				running = false;
				break;
			// By default, go to the main menu.
			case m_NONE:
			default:
				action = menuMain();
				break;
		}
	}

	return 0;
}
